﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DRHotel_v1.Classes;
using DRHotel_v1.Classes.DBManagers;

namespace DRHotel_v1.RoomAvaAndBooking
{
    public partial class InvoiceFrm : Form
    {
        public string roomNo;
        public string checkInDate;
        public string checkOutDate;
        public string adult;
        public string children;
        public string roomRate;
        public string days;
        public string ifLateCheckOut;
        public string extraFee;
        public string total;

        public InvoiceFrm()
        {
            InitializeComponent();
            printDocument3.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
        }

        //private PrintDocument printDocument2 = new PrintDocument();
        private PrintPreviewDialog printPreviewDialog2 = new PrintPreviewDialog();

        private void InvoiceFrm_Load(object sender, EventArgs e)
        {
            lblRoomID.Text = roomNo;
            lblCheckInDate.Text = checkInDate;
            lblCheckOutTime.Text = checkOutDate;
            lblAdult.Text = adult;
            lblChildren.Text = children;
            lblRoomRate.Text = roomRate;
            lblDays.Text = days;
            lblIfLate.Text = ifLateCheckOut;
            lblExtraFee.Text = extraFee;
            lblTotal.Text = total;
        }

        Bitmap memoryImage;
        private void CaptureScreen()
        {
            Graphics myGraphics = this.CreateGraphics();
            Size s = this.Size;
            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            memoryGraphics.CopyFromScreen(this.Location.X, Location.Y,0,0, s);
        }

        private void printDocument1_PrintPage(System.Object sender,
               System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 0, 0);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CaptureScreen();
            printPreviewDialog2.Document = printDocument3;
            printPreviewDialog2.ShowDialog();
        }

        #region practice
        private void printPreviewButton_Click(object sender, EventArgs e)
        {
            PrintPreviewDialog ppd = new PrintPreviewDialog();

            PrintDocument pd = new PrintDocument();

            pd.PrintPage += pd_PrintPage;

            ppd.Document = pd;

            ppd.ShowDialog();
        }

        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {

            Bitmap bmp = new Bitmap(groupBox1.ClientRectangle.Width, groupBox1.ClientRectangle.Height);

            groupBox1.DrawToBitmap(bmp, groupBox1.ClientRectangle);

            e.Graphics.DrawImage(bmp, 0, 0);

        }

        #endregion
    }
}
